/*
 * sdc.h
 *
 * Created: 2011.10.26 10:04:11
 *  Author: Administrator
 */ 


#ifndef SDC_H_
#define SDC_H_

#include <avr/io.h>

#define SDC_PORT	PORTB
#define SDC_CS		PB3
#define SDC_SS		PB4
#define SDC_MOSI	PB5
#define SDC_MISO	PB6
#define SDC_SCK		PB7

#define GO_IDLE_STATE	0
#define SEND_IF_COND	8
#define SEND_CSD		9
#define SEND_CID		10
#define SET_BLOCKLEN	16
#define READ_SINGLE_BLOCK		17
#define WRITE_BLOCK		24
#define SD_SEND_OP_COND	41
#define APP_CMD			55
#define CRC_ON_OFF		59
#define READ_OCR		58

#define SDC_ERROR			0x10

#define SDC_IN_IDLE_STATE	1

#define SDC_V1			2
#define SDC_V2			3
#define SDC_V2HC		4

#define SDC_READ_FINISH 5

#define SDC_WRITE_OK		5
#define SDC_WRITE_CRCERROR	0xb
#define SDC_WRITE_ERROR		0xd

unsigned char SDC_init();

unsigned char SDC_readblock(unsigned long addr,unsigned char buff[],unsigned short *crc16);
unsigned char SDC_writeblock(unsigned long addr,unsigned char buff[],unsigned short crc16);

#endif /* SDC_H_ */